﻿//------------------------------------------------------------------------------
// <copyright file="HandlersToMethodNameElementCollection.cs" company="CommerceServer.net, Inc">
//    (c) 2012 CommerceServer.net, Inc. and its affiliates. All rights reserved.
// </copyright>
// <summary></summary>
//------------------------------------------------------------------------------ 
namespace CommerceServerContrib.CodeGeneration.Configuration
{
    using System.Configuration;

    [ConfigurationCollection(typeof(HandlersToMethodNameElement), AddItemName = "handler")]
    public class HandlersToMethodNameElementCollection : ConfigurationElementCollection
    {
        /// <summary>
        /// Gets the <see cref="GenerationEntityElement" /> with the specified key.
        /// </summary>
        /// <param name="name">The key of the <see cref="RouteHandlerElementCollection" /> to retrieve.</param>
        /// <returns>Element with the given name.  </returns>
        public HandlersToMethodNameElement this[object name]
        {
            get
            {
                return (HandlersToMethodNameElement)this.BaseGet(name);
            }
        }

        public bool Contains(string name)
        {
            var exists = this.BaseGet(name);

            if (exists != null)
            {
                return true;
            }

            return false;
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new HandlersToMethodNameElement();
        }

        /// <summary>
        /// Gets the element key for a specified configuration element when overridden in a derived class.
        /// </summary>
        /// <param name="element">The <see cref="T:System.Configuration.ConfigurationElement"/> to return the key for.</param>
        /// <returns>
        /// An <see cref="T:System.Object"/> that acts as the key for the specified <see cref="T:System.Configuration.ConfigurationElement"/>.
        /// </returns>
        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((HandlersToMethodNameElement)element).Name;
        }
    }
}
